package com.itheima.udpguang;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/*
udp 的接收端
 */
public class ReceiveClient2 {

    public static void main(String[] args) throws IOException {
        //创建对象
        DatagramSocket ds = new DatagramSocket(8888);
        //容器
        byte[] bytes = new byte[1024 * 64];
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length);
        //接收数据
        ds.receive(dp);
        //接收到的数据的长度
        int length = dp.getLength();
        //查看数据
        System.out.println(new String(bytes,0,length));

        //释放资源
        ds.close();

    }
}
